﻿using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.SqlServer;
using CodeSaude.Domain.Entities;
using CodeSaude.Infrastructure.Data.EntityConfig;

namespace CodeSaude.Infrastructure.Data.Context
{
    public class CodeSaudeContext : DbContext
    {
        public CodeSaudeContext()
            : base("CodeSaudeConnection")
        {
            Database.SetInitializer<CodeSaudeContext>(null);
            var ensureDLLIsCopied = SqlProviderServices.Instance;
        }

        public IDbSet<Usuario> Usuario { get; set; }
        public IDbSet<GrupoUsuario> GrupoUsuario { get; set; }
        public IDbSet<Alergia> Alergia { get; set; }
        public IDbSet<LocalAtendimento> LocalAtendimento { get; set; }
        public IDbSet<Antecedente> Antecedente { get; set; }
        public IDbSet<LocalEspecialidade> LocalEspecialidade { get; set; }
        public IDbSet<Diagnostico> Diagnostico { get; set; }
        public IDbSet<DicionarioFonetico> DicionarioFonetico { get; set; }
        public IDbSet<Cuidado> Cuidado { get; set; }
        public IDbSet<Dieta> Dieta { get; set; }
        public IDbSet<Especialidade> Especialidade { get; set; }
        public IDbSet<Exame> Exame { get; set; }
        public IDbSet<Leito> Leito { get; set; }
        public IDbSet<Procedimento> Procedimento { get; set; }
        public IDbSet<Prontuario> Prontuario { get; set; }
        public IDbSet<ProntuarioAvaliacao> ProntuarioAvaliacao { get; set; }
        public IDbSet<Funcao> Funcao { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

            // Conventions
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();


            // ModelConfiguration
            modelBuilder.Configurations.Add(new UsuarioMap());
            modelBuilder.Configurations.Add(new GrupoUsuarioMap());
            modelBuilder.Configurations.Add(new AntecedenteMap());
            modelBuilder.Configurations.Add(new AlergiaMap());
            modelBuilder.Configurations.Add(new LocalEspecialidadeMap());
            modelBuilder.Configurations.Add(new LocalAtendimentoMap());
            modelBuilder.Configurations.Add(new DiagnosticoMap());
            modelBuilder.Configurations.Add(new DicionarioFoneticoMap());
            modelBuilder.Configurations.Add(new CuidadoMap());
            modelBuilder.Configurations.Add(new DietaMap());
            modelBuilder.Configurations.Add(new EspecialidadeMap());
            modelBuilder.Configurations.Add(new ExameMap());
            modelBuilder.Configurations.Add(new LeitoMap());
            modelBuilder.Configurations.Add(new ProcedimentoMap());
            modelBuilder.Configurations.Add(new ProntuarioMap());
            modelBuilder.Configurations.Add(new ProntuarioAvaliacaoMap());
            modelBuilder.Configurations.Add(new FuncaoMap());

            base.OnModelCreating(modelBuilder);
        }
    }
}
